package com.cleaningcloud.cld.controller;

import java.util.List;

import com.cleaningcloud.cld.domain.dto.CldMaterialConsumeDto;
import com.cleaningcloud.cld.domain.vo.CldMaterialConsumeVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.cleaningcloud.common.log.annotation.Log;
import com.cleaningcloud.common.log.enums.BusinessType;
import com.cleaningcloud.common.security.annotation.RequiresPermissions;
import com.cleaningcloud.cld.service.ICldMaterialConsumeService;
import com.cleaningcloud.common.core.web.controller.BaseController;
import com.cleaningcloud.common.core.web.domain.AjaxResult;
import com.cleaningcloud.common.core.utils.poi.ExcelUtil;
import com.cleaningcloud.common.core.web.page.TableDataInfo;

/**
 * 消耗记录Controller
 * 
 * @author cleaningcloud
 * @date 2024-10-28
 */
@RestController
@RequestMapping("/materialConsume")
public class CldMaterialConsumeController extends BaseController
{
    @Autowired
    private ICldMaterialConsumeService cldMaterialConsumeService;

    /**
     * 查询消耗记录列表
     */
    @RequiresPermissions("cld:materialConsume:list")
    @GetMapping("/list")
    public TableDataInfo list(CldMaterialConsumeDto cldMaterialConsume)
    {
        startPage();
        List<CldMaterialConsumeVo> list = cldMaterialConsumeService.selectCldMaterialConsumeList(cldMaterialConsume);
        return getDataTable(list);
    }


    /**
     * 查询项目消耗信息
     */
    @RequiresPermissions("cld:materialConsume:list")
    @GetMapping("/getProjectConsumeList")
    public TableDataInfo selectProjectConsumeList(CldMaterialConsumeDto cldMaterialConsume)
    {
        startPage();
        List<CldMaterialConsumeVo> list = cldMaterialConsumeService.selectCldMaterialConsumeProjectList(cldMaterialConsume);
        return getDataTable(list);
    }


    /**
     * 获取消耗记录详细信息
     */
    @RequiresPermissions("cld:materialConsume:query")
    @GetMapping(value = "/{materialConsumeId}")
    public AjaxResult getInfo(@PathVariable("materialConsumeId") Long materialConsumeId)
    {
        return success(cldMaterialConsumeService.selectCldMaterialConsumeByMaterialConsumeId(materialConsumeId));
    }

    /**
     * 新增消耗记录
     */
    @RequiresPermissions("cld:materialConsume:add")
    @Log(title = "消耗记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CldMaterialConsumeDto cldMaterialConsume)
    {
        return toAjax(cldMaterialConsumeService.insertCldMaterialConsume(cldMaterialConsume));
    }

    /**
     * 修改消耗记录
     */
    @RequiresPermissions("cld:materialConsume:edit")
    @Log(title = "消耗记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CldMaterialConsumeDto cldMaterialConsume)
    {
        return toAjax(cldMaterialConsumeService.updateCldMaterialConsume(cldMaterialConsume));
    }

    /**
     * 删除消耗记录
     */
    @RequiresPermissions("cld:materialConsume:remove")
    @Log(title = "消耗记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{materialConsumeIds}")
    public AjaxResult remove(@PathVariable Long[] materialConsumeIds)
    {
        return toAjax(cldMaterialConsumeService.deleteCldMaterialConsumeByMaterialConsumeIds(materialConsumeIds));
    }
}
